/**
 * Created by Administrator on 2017/6/27.
 */
define(['jquery', 'vue'], function ($, Vue) {
    var currentPage = 1;
    var keyword = "";
    var order = "id";
    var sort = "desc";

    // var _self;
    mui.init({
        pullRefresh: {
            container: '#refreshContainer',
            down: {
                height: 30,//可选,默认50.触发下拉刷新拖动距离,
                auto: false,//可选,默认false.自动下拉刷新一次
                contentdown: "正在刷新...",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
                contentover: "正在刷新...",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
                contentrefresh: "正在刷新...",//可选，正在刷新状态时，下拉刷新控件上显示的标题内容
                callback: pulldownRefresh//必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
            },
            up: {
                contentrefresh: '正在加载...',
                contentnomore: '没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
                callback: pullupRefresh
            }
        }
    });
    var vue = new Vue({
        el: '#data_ul',
        data: {
            items: []
        },
        methods: {
            detailbtn: function (id) {
                window.location.href = goods_url + "/store_id/" + id;
            }
        }
    });
    var vue2 = new Vue({
        el: '#vue_div',
        data: {},
        methods: {
            recharge_btn: function (id) {
                window.location.href = recharge_url;
            },
            withdraw_btn: function (id) {
                window.location.href = withdraw_url;
            }
        }
    });
    var vue3 = new Vue({
        el: '#info_ul',
        data: {
            info:""
        },
        methods: {

        }
    });
    $.get(account_url, {},
        function (result) {
            if (result.code === 1) {
                vue3.info= result.data;
            }
        });
    getData("up");
    function getData(flag) {
        var data = {
            'order': order,
            "sort": sort,
            "keyword": keyword,
            'page': currentPage
        };
        $.get(list_url, data,
            function (result) {
                if (result.code === 1) {
                    switch (flag) {
                        case "up":
                            if (result.data.length > 0) {
                                vue.items.push(result.data);
                                currentPage++;
                                mui('#refreshContainer').pullRefresh().endPullupToRefresh();
                            }
                            else {
                                mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
                            }
                            break;
                        case "down":
                            mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
                            break;
                    }
                }
            });
    }

    /**
     * 上拉加载具体业务实现
     */
    function pullupRefresh() {
        getData("up");
    }

    /**
     * 下拉刷新具体业务实现
     */
    function pulldownRefresh() {
        currentPage = 1;
        getData("down");
    }
});